package com.qianfeng.gl4study.youshare.acitivity.store;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.qianfeng.gl4study.youshare.adapters.CommonFragmentAdapter;
import com.qianfeng.gl4study.youshare.R;
import com.qianfeng.gl4study.youshare.fragments.TutorialImageFragment;
import com.qianfeng.gl4study.youshare.fragments.TutorialJumpFragment;
import com.qianfeng.gl4study.youshare.utils.Constants;

import java.util.LinkedList;
import java.util.List;

/**
 * 引导页
 * Created with IntelliJ IDEA.
 * I'm glad to share my knowledge with you all.
 * User:Gaolei
 * Date:2015/2/4
 * Email:pdsfgl@live.com
 */
public class TutorialActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tutorial);

        SharedPreferences sharedPreferences  = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        //向appdata文件写入数据，表明导航文件已经显示
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("tutorial.shown", true);
        // editor.commit();
        editor.apply();

        //初始化ViewPager
        ViewPager pager = (ViewPager) findViewById(R.id.tutorial_pager);
        List<Fragment> fragments = new LinkedList<Fragment>();

        //添加Fragment1
        TutorialImageFragment fragment = new TutorialImageFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("layoutId",R.layout.fragment_tutorial_image_1);
        fragment.setArguments(bundle);
        fragments.add(fragment);

        //添加Fragment2
        fragment = new TutorialImageFragment();
        bundle = new Bundle();
        bundle.putInt("layoutId",R.layout.fragment_tutorial_image_2);
        fragment.setArguments(bundle);
        fragments.add(fragment);

        //添加Fragment3
        fragment = new TutorialImageFragment();
        bundle = new Bundle();
        bundle.putInt("layoutId",R.layout.fragment_tutorial_image_3);
        fragment.setArguments(bundle);
        fragments.add(fragment);

        //添加Fragment4
        TutorialJumpFragment fragment1 = new TutorialJumpFragment();

        bundle = new Bundle();
        bundle.putInt("layoutId",R.layout.fragment_yutorial_jump);
        fragment1.setArguments(bundle);

        fragments.add(fragment1);

        //设置通用的Adapter
        CommonFragmentAdapter adapter = new CommonFragmentAdapter(getSupportFragmentManager(),fragments);
        pager.setAdapter(adapter);
    }

  /*
    public void onClickImage(View view){

        SharedPreferences sharedPreferences  = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        //向appdata文件写入数据，表明导航文件已经显示
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("tutorial.shown", true);
       // editor.commit();
        editor.apply();

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        this.finish();
    }
    */

}